import React, { Component } from "react";
import { connect } from "react-redux";
import { Layout, Menu, Breadcrumb, ConfigProvider,Modal } from "antd";
import { UserOutlined, } from "@ant-design/icons";
import "antd/dist/antd.css";
import { withRouter,Prompt } from "react-router-dom";
import { Route, Link, Router } from "react-router-dom";
import zhCN from 'antd/es/locale/zh_CN';
import { privateRoute } from "../routers";
var topMenus = privateRoute.filter((item) => {
    return item.isTop === true;
});

const confirm = Modal.confirm
// @withRouter
class Nav extends React.Component {
    constructor(props, context) {
        super(props, context);
        this.state={
            vis:false,
            logout:false,
        }
    }
    componentWillMount() {
        if (!sessionStorage.getItem('admin_key')) {
            this.props.history.push('/sign')
        }
    }
    onCancel=()=>{
        this.setState({
            vis:false,
            logout:false
        })
        return
    }
    onOk = ()=>{
        this.setState({
            vis:false,
            logout:true
        })
        this.props.history.push('/');
    }
    render() {
        const { SubMenu } = Menu;
        const { Header, Content, Footer, Sider } = Layout;
        return (
            <ConfigProvider locale={zhCN}>
                <Layout style={{ minHeight: "100%", minWidth: 1300 }}>
                    <Header className="admin_header">
                        <div className="logo"></div>
                    </Header>
                    <Content style={{ padding: "0 30px", height: '100%' }}>
                        <Layout
                            className="site-layout-background"
                            style={{ padding: "15px 0" }}
                        >
                            <Sider className="site-layout-background" width={200}>
                                <Menu
                                    mode="inline"
                                    defaultSelectedKeys={["1"]}
                                    defaultOpenKeys={["sub1"]}
                                    style={{ height: "100%" }}
                                    onClick={this.menusHandler}
                                >
                                    {topMenus.map((item) => {
                                        return (
                                            <Menu.Item key={item.pathname} style={{ margin: '5px 0' }}>{item.title}</Menu.Item>
                                        );
                                    })}
                                    <Menu.Item key='/' style={{ background: '#C6CAFC' }}>登出</Menu.Item>
                                </Menu>
                            </Sider>
                            <Content
                                style={{ padding: '15px 15px', minHeight: 280, height: "100%", background: 'white', marginLeft: 20 }}
                            >
                                {this.props.children}
                            </Content>
                        </Layout>
                    </Content>
                    <Footer style={{ textAlign: "center", padding: '15px 50px' }}>
                        Copyright©2017 版权所有 中国航天科工集团公司 备案序号:京ICP备05067351号
                        制作单位：中国航天科工集团
                        地址：北京市丰台区云岗北区西里1号　邮编：100074
        </Footer>
                </Layout>
                <Modal
                    visible={this.state.vis}
                    title=""
                    width="100"
                    okText="确认"
                    cancelText="取消"
                    onCancel={this.onCancel}
                    onOk={this.onOk}
                    >是否退出登录？</Modal>
            </ConfigProvider>
        );
    }
    menusHandler = ({ item, key, keyPath, domEvent }) => {
        if(key === "/"){
            this.setState({
                vis:true,
            })
            if(this.state.logout){
                // return
            }else{
                return
            }
        }
        this.props.history.push(key);
    };
}

export default withRouter(connect()(Nav));
